package com.bdq.user.api.client;

import cn.hutool.core.convert.Convert;
import com.bdq.common.entity.common.CommonResult;
import com.bdq.common.feign.user.UserFeign;
import com.bdq.common.feign.user.param.UserGetParam;
import com.bdq.common.feign.user.vo.UserFollowVO;
import com.bdq.common.feign.user.vo.UserGetVO;
import com.bdq.common.feign.user.vo.UserListVO;
import com.bdq.common.utils.StaticFileUtil;
import com.bdq.user.application.model.dto.UserFollowAppDTO;
import com.bdq.user.application.model.dto.UserGetAppDTO;
import com.bdq.user.application.model.dto.UserListAppDTO;
import com.bdq.user.application.model.query.UserGetQry;
import com.bdq.user.application.service.UserAppQueryService;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author malei
 * @date 2024-05-21 16:05
 */
@RestController
public class UserFeignImpl implements UserFeign {

    @Resource
    private UserAppQueryService userAppQueryService;

    @Override
    public CommonResult<UserGetVO> getUser(UserGetParam param) {
        UserGetAppDTO userGetAppDTO = userAppQueryService.getUser(Convert.convert(UserGetQry.class, param));
        userGetAppDTO.setAvatar(StaticFileUtil.domainConcat(userGetAppDTO.getAvatar()));
        return CommonResult.success(Convert.convert(UserGetVO.class, userGetAppDTO));
    }

    @Override
    public CommonResult<List<UserListVO>> listUser(List<Long> userIds) {
        List<UserListAppDTO> userList = userAppQueryService.listUser(userIds);
        return CommonResult.success(Convert.toList(UserListVO.class, userList));
    }

    @Override
    public CommonResult<List<UserFollowVO>> listUserFollow(Long followerUserId, List<Long> followedUserIds) {
        List<UserFollowAppDTO> userFollowAppDTOList = userAppQueryService.listUserFollow(followerUserId, followedUserIds);
        return CommonResult.success(Convert.toList(UserFollowVO.class, userFollowAppDTOList));
    }
}
